<?php

namespace App\Http\Controllers\Brand;

use App\Http\Controllers\BaseController;
use App\Models\BrandJoinPlan;
use App\Rules\Code;
use Illuminate\Http\Request;

class JoinPlanController extends BaseController
{

    public function show()
    {
        $plan = BrandJoinPlan::query()
                 ->where('user_id',auth('api')->id())
                ->first();

        return $this->success($plan);
    }

    public function store(Request $request)
    {
        $param = $this->validate($request,[
            'location_id' =>'required|integer',
            'profession_id' =>'required|integer',
            'investment_budget' => 'required',
            'plan_time' => 'required',
            'code' => ['required',new Code()]
        ]);

        $plan = BrandJoinPlan::query()->updateOrCreate(['user_id' => auth('api')->id()],$param);

        if ($plan->getKey()){
            return $this->success();
        }

        return  $this->error();
    }
}
